package Windows.DownLoads;

import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

public class DownloadTableModel extends AbstractTableModel {
	public static void main(String[] args) {
		JFrame frm = new JFrame("Dummy model demo.");
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		DownloadTableModel model = new DownloadTableModel();
		RatioRenderer renderer = new RatioRenderer();
		renderer.setForeground(Color.BLUE);
		JTable table = new JTable(model);
		table.setDefaultRenderer(Dimension.class, renderer);
		frm.getContentPane().add(new JScrollPane(table));
		frm.pack();
		frm.setVisible(true);
		Object[] obj = { "", "", "", "", "", "", new Dimension(10, 50), "", "", "", "" };

	}
	private String[] columnNames = { "安全", "资源名称", "类型", "评论", "文件大小", "已下载", "进度", "速度", "资源", "更新日期", "MD5" };
	private ArrayList<Object[]> al = new ArrayList<Object[]>(0);

	private Object[] data = { "", "", "", "", "", new StringBuffer(), new Dimension(0, 0), new StringBuffer(), new StringBuffer(), "", "" };

	public void addRow(Object[] obj) {
		al.add(obj);

	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return data[columnIndex].getClass();
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public String getColumnName(int columnIndex) {
		return columnNames[columnIndex];
	}

	@Override
	public int getRowCount() {
		return al.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (rowIndex < 0 || rowIndex >= al.size())
			return null;
		return al.get(rowIndex)[columnIndex];
	}

	public void removeRow(int row) {
		al.remove(row);
	}
}
